﻿using System;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Collections.Generic;
using System.Collections;
using System.Text.RegularExpressions;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.Data;
using System.Data.SqlClient;
using GeniePlugin;
using GeniePlugin.Interfaces;

namespace CommodityPlugin
{
    public enum CommodityMaster
    {
        Diamonds,
        Gold,
        Silver,
        Saffron,
        Pearls,
        Silk,
        Brass,
        Cinnamon,
        Slate,
        Limes,
        Purple_dye,
        Bronze,
        Oranges,
        Lead,
        Velvet,
        Lace,
        Taffelberries,
        Amber,
        Copper,
        Acanth,
        Myrrh,
        Indigo,
        Papyrus,
        Iron_ore,
        Barley,
        Oats,
        Wool,
        Wheat,
        Corn,
        Deobar_oil,
        Cotton,
        Salt,
        Apples,
        Charcoal
    };

    public enum StockType
    {
        SOLD_OUT,
        NEARLY_OUT,
        GOING_FAST,
        GOOD_STORES,
        SURPLUS
    };

    public class StockLimit
    {
        public CommodityMaster Commodity { get; set; }
        public int MinValue { get; set; }
        public int MaxValue { get; set; }
        public StockType CurrentStock { get; set; }

        public StockLimit(CommodityMaster ccComm, int iMin, int iMax, StockType stType)
        {
            this.Commodity = ccComm;
            this.CurrentStock = stType;
            this.MaxValue = iMax;
            this.MinValue = iMin;
        }

    }


    public class BreakingPoint
    {
        public CommodityMaster Commodity { get; set; }
        public int BreakingValue { get; set; }
        public int AvgPrice { get; set; }

        public BreakingPoint(CommodityMaster cmComm, int iValue, int iAvg)
        {
            this.Commodity = cmComm;
            this.BreakingValue = iValue;
            this.AvgPrice = iAvg;
        }
    }

    public class Plugin : GeniePlugin.Interfaces.IPlugin
    {

        #region IPlugin Members
        public IHost _host;                             //Required for plugin
        public System.Windows.Forms.Form _parent;       //Required for plugin

        public SqlConnection sqlCon = new SqlConnection("server=localhost;database=Commodity;uid=CommUser;password=CommPass;");

        
        public List<BreakingPoint> BreakingList = new List<BreakingPoint>();
        public List<StockLimit> StockList = new List<StockLimit>();

        /// <summary>
        /// Function should only be ran ONCE
        ///   At the very first run, if you make any changes to the code, be it altering custom breaking points (riskier trades) or setting other averages, they will be overwritten
        ///   if you modify this section
        /// </summary>
        protected void ReInitializeData()
        {
            #region BreakingPointInit
            BreakingList.Add(new BreakingPoint(CommodityMaster.Diamonds,      80,  1811));
                 BreakingList.Add(new BreakingPoint(CommodityMaster.Gold,      80, 1122));
               BreakingList.Add(new BreakingPoint(CommodityMaster.Silver,     160, 784));
              BreakingList.Add(new BreakingPoint(CommodityMaster.Saffron,      80, 765));
               BreakingList.Add(new BreakingPoint(CommodityMaster.Pearls,      80, 753));
                 BreakingList.Add(new BreakingPoint(CommodityMaster.Silk,      80, 577));
                BreakingList.Add(new BreakingPoint(CommodityMaster.Brass,     120, 454));
             BreakingList.Add(new BreakingPoint(CommodityMaster.Cinnamon,     160, 339));
                BreakingList.Add(new BreakingPoint(CommodityMaster.Slate,     160, 362));
                BreakingList.Add(new BreakingPoint(CommodityMaster.Limes,      80, 349));
           BreakingList.Add(new BreakingPoint(CommodityMaster.Purple_dye,      80, 280));
               BreakingList.Add(new BreakingPoint(CommodityMaster.Bronze,     100, 277));
              BreakingList.Add(new BreakingPoint(CommodityMaster.Oranges,     160, 260));
                 BreakingList.Add(new BreakingPoint(CommodityMaster.Lead,     240, 255));
               BreakingList.Add(new BreakingPoint(CommodityMaster.Velvet,      80, 225));
                 BreakingList.Add(new BreakingPoint(CommodityMaster.Lace,      80, 237));
        BreakingList.Add(new BreakingPoint(CommodityMaster.Taffelberries,     160, 192));
                BreakingList.Add(new BreakingPoint(CommodityMaster.Amber,     240, 188));
               BreakingList.Add(new BreakingPoint(CommodityMaster.Copper,     200, 194));
               BreakingList.Add(new BreakingPoint(CommodityMaster.Acanth,     160, 184));
                BreakingList.Add(new BreakingPoint(CommodityMaster.Myrrh,     100, 180));
               BreakingList.Add(new BreakingPoint(CommodityMaster.Indigo,     160, 155));
              BreakingList.Add(new BreakingPoint(CommodityMaster.Papyrus,     120, 147));
             BreakingList.Add(new BreakingPoint(CommodityMaster.Iron_ore,     400, 103));
               BreakingList.Add(new BreakingPoint(CommodityMaster.Barley,     320, 81));
                 BreakingList.Add(new BreakingPoint(CommodityMaster.Oats,     280, 91));
                 BreakingList.Add(new BreakingPoint(CommodityMaster.Wool,     320, 85));
                BreakingList.Add(new BreakingPoint(CommodityMaster.Wheat,     320, 71));
                 BreakingList.Add(new BreakingPoint(CommodityMaster.Corn,     320, 78));
           BreakingList.Add(new BreakingPoint(CommodityMaster.Deobar_oil,     200, 71));
               BreakingList.Add(new BreakingPoint(CommodityMaster.Cotton,     400, 77));
                 BreakingList.Add(new BreakingPoint(CommodityMaster.Salt,     400, 34));
               BreakingList.Add(new BreakingPoint(CommodityMaster.Apples,     280, 39));
               BreakingList.Add(new BreakingPoint(CommodityMaster.Charcoal, 560,   35));
            #endregion

            #region StockInits
               StockList.Add(new StockLimit(CommodityMaster.Diamonds, 1, 9, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Gold, 1, 9, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Silver, 1,19, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Saffron, 1,12, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Pearls, 1,10, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Silk, 1,10, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Brass, 1,15, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Cinnamon, 1, 21, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Slate, 1,20, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Limes, 1,12, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Purple_dye,1, 21, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Bronze, 1,11, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Oranges, 1,23, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Lead, 1,31, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Velvet, 1,12, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Lace, 1,12, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Taffelberries, 1, 22, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Amber, 1,14, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Copper, 1,26, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Acanth, 1,19, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Myrrh, 1,12, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Indigo, 1,20, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Papyrus, 1,14, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Iron_ore, 1,51, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Barley, 1,42, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Oats, 1,37, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Wool, 1,39, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Wheat, 1,43, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Corn, 1,116, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Deobar_oil, 1, 25, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Cotton, 1,48, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Salt, 1,49, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Apples, 1,37, StockType.NEARLY_OUT));
               StockList.Add(new StockLimit(CommodityMaster.Charcoal, 1,71, StockType.NEARLY_OUT));

               StockList.Add(new StockLimit(CommodityMaster.Diamonds, 10,49, StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Gold, 10,49,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Silver, 20,99,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Saffron,7,52,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Pearls, 10,49,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Silk, 8,49,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Brass, 15,74,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Cinnamon, 16,99,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Slate, 18,99,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Limes, 8,52,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Purple_dye, 5,50,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Bronze, 11,61,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Oranges, 16,102,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Lead, 28,149,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Velvet, 8,50,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Lace, 8,50,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Taffelberries, 16,102,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Amber, 140,147,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Copper, 23,122,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Acanth, 19,97,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Myrrh, 10,63,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Indigo, 18,98,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Papyrus, 15,72,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Iron_ore, 49,121,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Barley, 37,193,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Oats, 32,174,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Wool, 39,196,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Wheat, 37,199,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Corn, 37,200,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Deobar_oil, 23,124,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Cotton, 50,249,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Salt, 50,245,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Apples, 32,158,StockType.GOING_FAST));
               StockList.Add(new StockLimit(CommodityMaster.Charcoal, 71,327,StockType.GOING_FAST));

               StockList.Add(new StockLimit(CommodityMaster.Diamonds, 50,79,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Gold, 50,79,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Silver, 100,159,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Saffron,46,82,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Pearls, 50,79,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Silk, 50,81,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Brass, 75,119,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Cinnamon, 100,163,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Slate, 100,160,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Limes, 49,82,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Purple_dye, 48,80,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Bronze, 62,99,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Oranges, 97,162,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Lead, 151,240,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Velvet, 48,79,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Lace, 48,79,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Taffelberries, 98,160,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Amber, 152,240,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Copper, 126,199,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Acanth, 98,159,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Myrrh, 61,99,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Indigo, 98,160,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Papyrus, 75,120,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Iron_ore, 286,399,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Barley, 210,320,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Oats, 175,281,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Wool, 203,319,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Wheat, 213,321,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Corn, 200,321,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Deobar_oil, 126,198,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Cotton, 249,399,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Salt, 262,395,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Apples, 184,282,StockType.GOOD_STORES));
               StockList.Add(new StockLimit(CommodityMaster.Charcoal, 386,560,StockType.GOOD_STORES));


               StockList.Add(new StockLimit(CommodityMaster.Diamonds, 80,100,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Gold, 80,100,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Silver, 160,165,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Saffron,77,100,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Pearls, 80,100,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Silk, 79,100,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Brass, 120,136,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Cinnamon, 156,200,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Slate, 158,200,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Limes, 78,100,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Purple_dye, 80,100,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Bronze, 100,125,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Oranges, 158,200,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Lead, 240,300,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Velvet, 80,100,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Lace, 80,100,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Taffelberries, 156,200,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Amber, 240,303,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Copper, 200,250,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Acanth, 159,200,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Myrrh, 98,125,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Indigo, 158,200,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Papyrus, 120,150,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Iron_ore, 399,500,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Barley, 318,400,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Oats, 276,350,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Wool, 319,400,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Wheat, 317,400,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Corn, 319,400,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Deobar_oil, 200,250,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Cotton, 400,500,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Salt, 417,500,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Apples, 278,350,StockType.SURPLUS));
               StockList.Add(new StockLimit(CommodityMaster.Charcoal, 559, 700, StockType.SURPLUS));


            #endregion

            #region Triggers
            /*  Triggers, Incase they are overwritten
             * 
            #trigger {Diamonds[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Diamonds.Units $1; #var Diamonds.Stock $2}
            #trigger {Gold[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Gold.Units $1; #var Gold.Stock $2}
            #trigger {Silver[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Silver.Units $1; #var Silver.Stock $2}
            #trigger {Saffron[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Saffron.Units $1; #var Saffron.Stock $2}
            #trigger {Pearls[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Pearls.Units $1; #var Pearls.Stock $2}
            #trigger {Silk[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Silk.Units $1; #var Silk.Stock $2}
            #trigger {Brass[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Brass.Units $1; #var Brass.Stock $2}
            #trigger {Cinnamon[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Cinnamon.Units $1; #var Cinnamon.Stock $2}
            #trigger {Slate[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Slate.Units $1; #var Slate.Stock $2}
            #trigger {Limes[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Limes.Units $1; #var Limes.Stock $2}
            #trigger {Purple Dye[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Purple_dye.Units $1; #var Purple_dye.Stock $2}
            #trigger {Bronze[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Bronze.Units $1; #var Bronze.Stock $2}
            #trigger {Oranges[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Oranges.Units $1; #var Oranges.Stock $2}
            #trigger {Lead[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Lead.Units $1; #var Lead.Stock $2}
            #trigger {Velvet[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Velvet.Units $1; #var Velvet.Stock $2}
            #trigger {Lace[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Lace.Units $1; #var Lace.Stock $2}
            #trigger {Taffelberries[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Taffelberries.Units $1; #var Taffelberries.Stock $2}
            #trigger {Amber[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Amber.Units $1; #var Amber.Stock $2}
            #trigger {Copper[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Copper.Units $1; #var Copper.Stock $2}
            #trigger {Acanth[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Acanth.Units $1; #var Acanth.Stock $2}
            #trigger {Myrrh[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Myrrh.Units $1; #var Myrrh.Stock $2}
            #trigger {Indigo[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Indigo.Units $1; #var Indigo.Stock $2}
            #trigger {Papyrus[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Papyrus.Units $1; #var Papyrus.Stock $2}
            #trigger {Iron ore[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Iron_ore.Units $1; #var Iron_ore.Stock $2}
            #trigger {Barley[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Barley.Units $1; #var Barley.Stock $2}
            #trigger {Oats[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Oats.Units $1; #var Oats.Stock $2}
            #trigger {Wool[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Wool.Units $1; #var Wool.Stock $2}
            #trigger {Wheat[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Wheat.Units $1; #var Wheat.Stock $2}
            #trigger {Corn[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Corn.Units $1; #var Corn.Stock $2}
            #trigger {Deobar oil[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Deobar_oil.Units $1; #var Deobar_oil.Stock $2}
            #trigger {Cotton[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Cotton.Units $1; #var Cotton.Stock $2}
            #trigger {Salt[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Salt.Units $1; #var Salt.Stock $2}
            #trigger {Apples[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Apples.Units $1; #var Apples.Stock $2}
            #trigger {Charcoal[ ]{1,15}([0-9]{0,5})[ ]{1,15}(Nearly Out!|Surplus!|Good Stores|Going Fast)} {#var Charcoal.Units $1; #var Charcoal.Stock $2}
            #trigger {[Traders' Guild, The Pit]} {read board}
*/
            #endregion
        }


        string GeniePlugin.Interfaces.IPlugin.Author
        {
            get { return "Rico"; }
        }

        string GeniePlugin.Interfaces.IPlugin.Description
        {
            get { return "Plugin will Track and Do some crazy logging stuff for Commodities.   Hopefully"; }
        }

        bool GeniePlugin.Interfaces.IPlugin.Enabled
        {
            get;
            set;
        }

        void GeniePlugin.Interfaces.IPlugin.Initialize(GeniePlugin.Interfaces.IHost Host)
        {
            _host = Host;

            this.sqlCon.Open();
        }

        string GeniePlugin.Interfaces.IPlugin.Name
        {
            get { return "Commodity Tracker"; }
        }

        void GeniePlugin.Interfaces.IPlugin.ParentClosing()
        {
        }

        string GeniePlugin.Interfaces.IPlugin.ParseInput(string Text)
        {

            if (Text.ToLower().Contains("/commload") || Text.ToLower().Contains("/loadcomm"))
            {
                // We have a board to read!  Lets save the Data

                Array values = Enum.GetValues(typeof(CommodityMaster));

                foreach (CommodityMaster val in values)
                {
                    SqlCommand sqlCmd = new SqlCommand("SaveData", sqlCon);
                    sqlCmd.CommandType = CommandType.StoredProcedure;
                    sqlCmd.Parameters.Add(new SqlParameter("@Location", this._host.get_Variable("CurrLoc")));
                    sqlCmd.Parameters.Add(new SqlParameter("@Commodity", val.ToString()));
                    sqlCmd.Parameters.Add(new SqlParameter("@CommPrice", this._host.get_Variable(val.ToString() + ".Units")));
                    sqlCmd.Parameters.Add(new SqlParameter("@Stock", this._host.get_Variable(val.ToString() + ".Stock")));
                    int i = sqlCmd.ExecuteNonQuery();

                }

            }
            else if (Text.ToLower().Contains("/commrep"))
            {


            }

            return Text;
        }

        string GeniePlugin.Interfaces.IPlugin.ParseText(string Text, string Window)
        {
            return Text;
        }

        void GeniePlugin.Interfaces.IPlugin.ParseXML(string XML)
        {
            
        }

        void GeniePlugin.Interfaces.IPlugin.Show()
        {
            //throw new NotImplementedException();
        }

        void GeniePlugin.Interfaces.IPlugin.VariableChanged(string Variable)
        {
            // Check if the current Variable to Change, is part of the commodity List

        }

        string GeniePlugin.Interfaces.IPlugin.Version
        {
            get { return "Alpha"; }
        }

        #endregion
    }
}
